package com.zjw.touchscreen.listener;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;

@SuppressLint("NewApi")
public class KeyboardBounceClickListener implements View.OnClickListener {

    private Context context;
    private EditText editText;

    public KeyboardBounceClickListener(Context context, EditText editText) {
        this.context = context;
        this.editText = editText;
    }

    @Override
    public void onClick(View v) {
        InputMethodManager imm = context.getSystemService(InputMethodManager.class);
        if (v instanceof ImageView) {
            // 弹出软键盘
            editText.setFocusable(true);
            editText.setFocusableInTouchMode(true);
            editText.requestFocus();
            imm.showSoftInput(editText, 0);
        } else {
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
        }

    }
}
